﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Abp.Authorization.Users;
using Abp.Extensions;
using Microsoft.AspNet.Identity;
using SingleUserMall.Orders;

namespace SingleUserMall.Authorization.Users
{
    public class User : AbpUser<User>
    {
        public virtual ICollection<Order> Orders { get; set; }
        /// <summary>
        /// 头像
        /// </summary>
        public string Avatar { get; set; }
        /// <summary>
        /// 性别（0-未知，1-男，2-女）
        /// </summary>
        public Gender Gender { get; set; }

        /// <summary>
        /// 是否关注
        /// </summary>
        public Subscribe? Subscribes { get; set; }

        /// <summary>
        /// openId
        /// </summary>
        public string OpenId { get; set; }
        /// <summary>
        /// 个人体验金
        /// </summary>
        public decimal Points { get; set; }
        /// <summary>
        /// 个人已释放体验金
        /// </summary>
        public decimal CanUsePoints { get; set; }
        /// <summary>
        /// 源用户id
        /// </summary>
        public long? SourceUserId { get; set; }
        /// <summary>
        /// 反向二级用户id
        /// </summary>
        public long? GrandUserId { get; set; }
        /// <summary>
        /// 个人佣金
        /// </summary>
        public decimal Commision { get; set; }
        /// <summary>
        /// 是否管理员
        /// </summary>
        public bool IsAdmin { get; set; }
        /// <summary>
        /// 是否是会员
        /// </summary>
        public bool IsVip { get; set; }
        /// <summary>
        /// 会员等级
        /// </summary>
        public int VipLevel { get; set; }
        /// <summary>
        /// 是否推广大使
        /// </summary>
        public bool IsPromotion { get; set; }
        /// <summary>
        /// 亲情号
        /// </summary>
        public long? PartnerUserId { get; set; }
        /// <summary>
        /// 亲情号角色
        /// </summary>
        public string PartnerRole { get; set; }
        /// <summary>
        /// 申请店铺成功后的用户Id
        /// </summary>
        public long? ManagerUserId { get; set; }
        /// <summary>
        /// 用户所在地
        /// </summary>
        public string UserLocation { get; set; }
        /// <summary>
        /// 用户年龄段
        /// </summary>
        public string UserAge { get; set; }

        /// <summary>
        /// 个人红包金额
        /// </summary>
        public decimal UserRedPacket { get; set; }
        /// <summary>
        /// 用户收入
        /// </summary>
        public UserIncomeStatus UserIncome { get; set; }

        /// <summary>
        /// 购买分红产品消费额
        /// </summary>
        public decimal SumConsumptionAmount{get;set;}

        /// <summary>
        /// 购买分红产品获得利润
        /// </summary>
        public decimal SumDividendAmount { get; set; }
        /// <summary>
        /// 性别
        /// </summary>
        public string UserSex { get; set; }

        /// <summary>
        /// 用户钱包金额
        /// </summary>
        public decimal UserWallet { get; set; }
        /// <summary>
        /// 用户身份证号
        /// </summary>
        public string UserIdCardNO { get; set; }
        /// <summary>
        /// 真实姓名
        /// </summary>
        public string TrueName { get; set; }
        /// <summary>
        /// 代理等级
        /// </summary>
        public int AgencyLevel { get; set; }
        /// <summary>
        /// 身份证图片
        /// </summary>
        public string IdCardImg { get; set; }

        public const string DefaultPassword = "123456";

        public static string CreateRandomPassword()
        {
            return Guid.NewGuid().ToString("N").Truncate(16);
        }

        public static User CreateTenantAdminUser(int tenantId, string emailAddress, string password)
        {
            var user = new User
            {
                TenantId = tenantId,
                UserName = AdminUserName,
                Name = AdminUserName,
                Surname = AdminUserName,
                EmailAddress = emailAddress,
                Password = new PasswordHasher().HashPassword(password)
            };

            return user;
        }
        /// <summary>
        /// 是否关注
        /// </summary>
        public enum Subscribe : int {

            /// <summary>
            /// 未关注
            /// </summary>
            [Description("未关注")]
            Subscribetrue = 0,
            /// <summary>
            /// 已关注
            /// </summary>
            [Description("已关注")]
            Subscribefalse = 1
        }


        public enum UserIncomeStatus : int
        {
            /// <summary>
            /// 高收入
            /// </summary>
            [Description("高收入")]
            HighIncome = 3,
            /// <summary>
            /// 中收入
            /// </summary>
            [Description("中收入")]
            MiddleIncome = 2,
            /// <summary>
            /// 低收入
            /// </summary>
            [Description("低收入")]
            LowIncome = 1,
            /// <summary>
            /// 全部
            /// </summary>
            [Description("全部")]
            All = 0
        }
    }
}